package model

import (
	"github.com/starmotioncf/common/third_account"

	"gorm.io/gorm"
)

// UserAuth 用户认证模型结构定义
// 对应数据库表`user_auth`
type UserAuth struct {
	Id           int                        `gorm:"column:id;primaryKey;autoIncrement;type:bigint(20) unsigned" json:"id"`                                                        // ID主键
	Uid          uint64                     `gorm:"column:uid;not null" json:"uid"`                                                                                               // 用户id
	IdentityType third_account.IdentityType `gorm:"column:identity_type;not null;type:tinyint(4);uniqueIndex:idx_iden(identity_type,identifier,deleted_at)" json:"identity_type"` // 第三方登录
	Identifier   string                     `gorm:"column:identifier;not null;size:200" json:"identifier"`                                                                        // 标识id
	Credential   string                     `gorm:"column:credential;not null;default:'';size:1000" json:"credential"`                                                            // 密码或凭证
	Account      string                     `gorm:"column:account;not null;default:'';size:100" json:"account"`                                                                   // 第三方账号
	AccessToken  string                     `gorm:"column:access_token;not null;default:'';size:1000" json:"access_token"`                                                        // 登录token
	Nickname     string                     `gorm:"column:nickname;not null;default:'第三方账号昵称';size:100" json:"nickname"`                                                          // 第三方账号昵称
	Binding      int8                       `gorm:"column:binding;not null;default:0;type:tinyint(4)" json:"binding"`                                                             // 是否绑定
	CreatedAt    int64                      `gorm:"column:created_at;not null" json:"created_at"`                                                                                 // 注册时间
	UpdatedAt    int64                      `gorm:"column:updated_at;not null;default:0" json:"updated_at"`                                                                       // 最后更新时间
	DeletedAt    gorm.DeletedAt             `gorm:"column:deleted_at;type:bigint(20);not null;default:0;index:idx_uid" json:"deleted_at"`                                         // 解绑删除
}

func (UserAuth) TableName() string {
	return "user_auth"
}

// UserRegisterInfo 对应user_register_info表结构
type UserRegisterInfo struct {
	Id          int    `gorm:"primaryKey;autoIncrement;column:id"`
	Uid         uint64 `gorm:"column:uid;default:0;comment:'uid';index:uid"`
	Mac         string `gorm:"column:mac;type:varchar(64);default:'';comment:'注册mac'"`
	Ip          string `gorm:"column:ip;type:varchar(32);default:'';comment:'注册ip'"`
	Platform    string `gorm:"column:platform;type:varchar(25);default:'0';comment:'平台'"`
	AppVer      string `gorm:"column:app_ver;type:varchar(25);default:'';comment:'app版本'"`
	OsVer       string `gorm:"column:os_ver;type:varchar(25);default:'';comment:'系统版本'"`
	Model       string `gorm:"column:model;type:varchar(50);default:'';comment:'手机型号'"`
	Simcard     int8   `gorm:"column:simcard;default:0;comment:'是否有sim，0否1是'"`
	Emulator    string `gorm:"column:emulator;type:varchar(100);default:''"`
	AuthID      int    `gorm:"column:auth_id;default:0;comment:'对应user_auth表'"`
	Region      uint64 `gorm:"column:region;default:0;comment:'分区'"`
	CountryCode string `gorm:"column:country_code;type:varchar(2);default:'';comment:'国家'"`
	Channel     uint8  `gorm:"column:channel;default:0;comment:'下载渠道，1谷歌 2苹果 3华为 4官网'"`
	CreatedAt   int64  `gorm:"column:created_at;default:0;comment:'注册时间'"`
}

// TableName 设置表名
func (u *UserRegisterInfo) TableName() string {
	return "user_register_info"
}

// UserLoginRecord 对应user_login_record表结构
type UserLoginRecord struct {
	ID          int    `gorm:"primaryKey;autoIncrement;column:id"`
	UID         uint64 `gorm:"primaryKey;column:uid;comment:'登陆用户';index:idx_uid"`
	Mac         string `gorm:"column:mac;type:varchar(100);default:'';comment:'登陆设备';index:idx_mac"`
	Ip          string `gorm:"column:ip;type:varchar(100);default:'';comment:'登陆IP';index:idx_ip"`
	Model       string `gorm:"column:model;type:varchar(50);default:'';comment:'登陆手机'"`
	AppVer      string `gorm:"column:app_ver;type:varchar(25);default:'';comment:'登陆app版本'"`
	OsVer       string `gorm:"column:os_ver;type:varchar(25);comment:'系统版本'"`
	Platform    string `gorm:"column:platform;type:varchar(25);comment:'平台'"`
	AuthID      int    `gorm:"column:auth_id;default:0;comment:'登录类型，对应表user_auth.id'"`
	AccessToken string `gorm:"column:access_token;type:varchar(1000);default:'';comment:'登陆token'"`
	CountryCode string `gorm:"column:country_code;type:varchar(2);comment:'国家'"`
	Region      uint64 `gorm:"column:region;default:0;comment:'分区'"`
	Channel     uint8  `gorm:"column:channel;default:0;comment:'登陆包渠道'"`
	CreatedAt   int64  `gorm:"column:created_at;default:0;comment:'登陆时间'"`
}

// TableName 设置表名
func (u *UserLoginRecord) TableName() string {
	return "user_login_record"
}
